<?php
require_once './core/tools.php';

if (!isset($_GET["id_swf"]))
	die('{"error":1, "message":"missing_parameter"');

$query = "SELECT * FROM versions_swf WHERE id_swf='".$_GET["id_swf"]."'";
$result = executeSQL($query);
if (!$result){
	die ('{"error":1, "message":"MysqlError :'.addslashes(mysql_error()).'"}' );
}

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
	$id_swf = $row["id_swf"];
	$title = $row["name"];
	$major = $row["major"];
	$minor = $row["minor"];
	$build = $row["build"];
}


?>

<script type="text/javascript">
	function cancelEdit() {
		$('#popin').html("");
		$('#popin').css("display", "none");
	}
	
	function validEdit() {
	
		
		$.ajax({
			url: 'update.php',
			type: "POST",
			data: {title: $('[name=title]').val(), major: $('[name=major]').val(), minor: $('[name=minor]').val(), build: $('[name=build]').val(), id_swf: $('[name=id_swf]').val()},
			success: function(data) {
				var response = jQuery.parseJSON(data);
						
				if (response.error == 0){
					document.location.reload();
				}
				else {
					console.log('Update failed, reason: ' + response.message);
				}
			},
			error: function (jqXHR) {
				console.log("call failed " + jqXHR);
			}

		});

	}

</script>


<div class="header"></div>
<div class="overlay">
	<p class="title"><img src="medias/bullet_wrench.png" class="icone"/>Edit</p>
	<form id="editForm">
		<p>title <input type="text" name="title" value="<?php echo($title); ?>"></p>
		<p>major <input type="text" name="major" value="<?php echo($major); ?>"></p>
		<p>minor <input type="text" name="minor" value="<?php echo($minor); ?>"></p>
		<p>build <input type="text" name="build" value="<?php echo($build); ?>"></p>
		<input type="hidden" name="id_swf" value="<?php echo($id_swf); ?>" />
		<p><a href="#" class="button" onClick="cancelEdit()">Cancel</a><a href="#"  class="button" style="float: right;" onClick="validEdit()">Ok</a></p>
	</form>
</div>

		
